package com.geek.javase.Game;

import java.sql.SQLOutput;
import java.util.Random;

/**
 * @author chenshupeng
 * @date 2025/9/3
 * @desc TODO
 **/

public class Hero extends Role {

     //一对多关联英雄  数组默认下标从0开始
     private Equip[] equips = new Equip[3];
     //英雄的计数器
     private int index = 0;
         public void addEquip(Equip e){
         if(index>=equips.length){
             System.out.println("装备已满");
             return;
         }

         //添加装备
         equips[index++] = e;
         //合并攻击力
             this.setDefence(this.getDefence()+e.getPower());
         //合并防御力
             this.setDefence(this.getDefence()+e.getDefence());
     }
     public void showEquip()//按F检视装备
     {

     }
    public  void attack(Role m)
    {
       int random= (int)(Math.random()*100+1);

       if(m.getBlood()>0)
        {
            if (random <= 40)    //暴击率百分之四十，造成攻击力2倍伤害
            {
                System.out.println(this.getName() + "打出暴击，造成" + this.getPower() * 3 + "伤害");
                m.setBlood(m.getBlood() - this.getPower() * 3);//重新设置怪兽血量
            }
            else
            {
                System.out.println(this.getName() + "造成" + this.getPower() + "伤害");
                m.setBlood(m.getBlood() - this.getPower());
            }
        }
    }

    public Hero(String name, String kind, int blood, int power, int defence, int level) {
      super(name,kind,blood,power,defence,level);
    }

}
